using HSGD.Common.Caches;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System.Collections.Frozen;

namespace HSGD.Api.Controllers {
    [ApiController]
    [Route("[controller]")]
    [Authorize("Permission")]

    public class WeatherForecastController : ControllerBase {
        private static readonly string[] Summaries =
        [
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        ];
        private readonly ILogger<WeatherForecastController> _logger;
        private readonly ICaching _caching;

        public WeatherForecastController(ILogger<WeatherForecastController> logger,
            ICaching caching) {
            _logger = logger;
            _caching = caching;
        }

        [HttpGet(Name = "GetWeatherForecast")]
        public async Task<object> Get() {

            //var userService = new UserService();
            //var userList = await userService.Query();
            //return userList;

            //var roleService = new BaseServices<Role, RoleVo>(_mapper);
            //var roleList = await roleService.Query();
            //var roleList = await roleServiceObj.Query();
            ////var roleList = await _roleService.Query();
            //return roleList;
            await Task.CompletedTask;
            return "ok";
        }

        [HttpGet]
        [Route("api/test")]
        public async Task<object> Test() {

            //$@"Error load  assembly.".WriteErrorLine();

            //var user = App.GetService<IUserService>(false);
            //var res = await user.Query();
            //var res = 123;

            var cacheKey = "cache-key";
            List<string> cacheKeys = await _caching.GetAllCacheKeysAsync();
            await Console.Out.WriteLineAsync($" All Keys:{JsonConvert.SerializeObject(cacheKey)}");
            await _caching.SetStringAsync(cacheKey, "Hello world!!!");
            await Console.Out.WriteLineAsync($" All Keys:{JsonConvert.SerializeObject(await _caching.GetAllCacheKeysAsync())}");
            await Console.Out.WriteLineAsync($" Current Context:{JsonConvert.SerializeObject(await _caching.GetStringAsync(cacheKey))}");

            await Console.Out.WriteLineAsync($" Delete Keys");
            await _caching.RemoveAsync(cacheKey);
            await Console.Out.WriteLineAsync($" All Keys:{JsonConvert.SerializeObject(await _caching.GetAllCacheKeysAsync())}");
            //var roleList = await _roleService.Query();
            //Console.WriteLine(_roleService.GetHashCode());
            //var roleList2 = await _roleService.Query();
            //Console.WriteLine(_roleService.GetHashCode());
            //return roleList;
            //Log.Information($"{DateTime.Now}");
            //var res = await _userService.Query();
            //return res;
            await Task.CompletedTask;
            return "ok";
        }

        //[HttpGet]
        //[Route("api/test1")]
        //public async Task<object> Test1(){
        //    return ok(2123)
        //}
    }
}
